package com.example.backend.controller;

import com.example.backend.Utils.WeatherUtil;
import com.example.backend.model.ResBean;
import com.example.backend.model.WeatherData;
import com.example.backend.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/device", produces = "application/json;charset=UTF-8")
public class DeviceController {

    private DeviceService deviceService;

    @Autowired
    public DeviceController(DeviceService deviceService) {
        this.deviceService = deviceService;
    }

    /**
     * 打开设备
     */
    @PutMapping("/open")
    public ResBean openDevice(@RequestParam String deviceName) {
        String res = this.deviceService.openDevice(deviceName);
        return new ResBean(res);
    }

    /**
     * 关闭设备
     */
    @PutMapping("/close")
    public ResBean closeDevice(@RequestParam String deviceName) {
        String res = this.deviceService.closeDevice(deviceName);
        return new ResBean(res);
    }
}
